;;; package --- Summary
;;
;;; Commentary:
;;;
;;; Code:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(auto-save-file-name-transforms '((".*" "~/.emacs.d/autosaves/\\1" t)))
 '(backup-directory-alist '((".*" . "~/.emacs.d/backups/")))
 '(backward-delete-char-untabify-method 'hungry)
 '(default-tab-width 4)
 '(gc-cons-threshold 100000000)
 '(global-auto-revert-mode 1)
 '(inhibit-startup-screen t)
 '(package-selected-packages
   '(go-guru go-imenu imenu-anywhere lsp-ui lsp-mode go-mode smex counsel-projectile nyan-mode yasnippet-snippets yasnippet flycheck company sr-speedbar smartparens avy counsel ivy diminish undo-tree winum use-package))
 '(ring-bell-function 'ignore)
 '(show-trailing-whitespace 1))

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

(fset 'yes-or-no-p 'y-or-n-p)
(display-time)
(column-number-mode t)
(show-paren-mode t)
;; treat underscore as part of the word
(modify-syntax-entry ?_ "w")
;; create the autosave dir if necessary, since emacs won't.
(make-directory "~/.emacs.d/autosaves/" t)
;; xterm mouse enable
(xterm-mouse-mode t)

;; Emacs builtin
(require 'package)

;; set package.el repo
(setq package-archives
	  '(
		("gnu"   . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
		("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")
		)
	  )

;; init built-in package mgmt
(package-initialize)

;; update packages list if we are on a new install
(unless package-archive-contents
  (package-refresh-contents))

;; install pkgs, mainly for use-package pkg.
(package-install-selected-packages)



;;
;; bookmark
;;
(use-package bookmark
  :ensure t
  :bind (("C-!" . (lambda() (interactive) (bookmark-set "mybm1")))
		 ("C-*" . (lambda() (interactive) (bookmark-set "mybm8")))
		 ("C-(" . (lambda() (interactive) (bookmark-set "mybm9")))
		 ("C-)" . (lambda() (interactive) (bookmark-set "mybm0")))
		 ("C-1" . (lambda() (interactive) (bookmark-jump "mybm1")))
		 ("C-8" . (lambda() (interactive) (bookmark-jump "mybm8")))
		 ("C-9" . (lambda() (interactive) (bookmark-jump "mybm9")))
		 ("C-0" . (lambda() (interactive) (bookmark-jump "mybm0"))))
  )

;;
;; recentf
;;
(use-package recentf
  :ensure t
  :custom (recentf-max-menu-item 15)
  :bind (("C-x C-b" . counsel-buffer-or-recentf))
  :config
  (recentf-mode t)
  )

;;
;; xref
;;
(use-package xref
  :ensure t
  :bind (("C-." . xref-find-definitions)
		 ("C-," . xref-pop-marker-stack)
		 ;;("C-;" . xref-find-references)
		 )
  )

;;
;; linum
;;
(use-package linum
  :ensure t
  :custom (linum-format "%04d: ")
  :config
  (global-linum-mode t)
  )

;;
;; winum
;;

(use-package winum
  :ensure t
  :defer nil
  :bind (
         ("M-1" . winum-select-window-1)
         ("M-2" . winum-select-window-2)
         ("M-3" . winum-select-window-3)
         ("M-4" . winum-select-window-4)
         ("M-5" . winum-select-window-5)
         ("M-6" . winum-select-window-6)
         ("M-7" . winum-select-window-7)
         ("M-8" . winum-select-window-8)
         )
  :config
  (winum-mode)
  )

;;
;; undo tree
;;
(use-package undo-tree  :ensure t)

;;
;; diminish
;;
(use-package diminish :ensure t)

;;
;; ivy mode
;;
(use-package ivy
  :ensure t
  :diminish (ivy-mode . " I")
  :config
  (ivy-mode 1)
  )

;;
;; counsel
;;
(use-package counsel
  :ensure t
  :bind (("M-x" . counsel-M-x)
		 ("C-x C-f" . counsel-find-file))
  :config
  (use-package smex
	:ensure t)
  )

;;
;; swiper
;;
(use-package swiper
  :ensure t
  :bind (("C-s" . swiper))
  )

;;
;; avy
;;
(use-package avy
  :ensure t
  :bind (("C-c SPC" . avy-goto-char-timer)
		 ("M-g g" . avy-goto-line))
  )

;;
;; smartparens
;;

(use-package smartparens
  :ensure t
  :bind (
		 ("C-]" . (lambda(arg)
					(interactive "p")
					(cond ((looking-at "\\s(") (forward-list 1) (backward-char 1))
						  ((looking-at "\\s)") (forward-char 1) (backward-list 1))
						  (t (self-insert-command (or arg 1))))))
		 )
  :config
  (smartparens-global-mode t)
  )


;;
;; speedbar
;;
(use-package speedbar
  :ensure t
  :config
  (set-variable 'speedbar-use-images nil)
  )

;;
;; sr speedbar
;;
(use-package sr-speedbar
  :ensure t
  :bind (("<f5>" . (lambda()
		     (interactive)
		     (sr-speedbar-toggle))))
  :custom
  (sr-speedbar-right-side nil)
  (sr-speedbar-width 35)
  :config
  (speedbar-add-supported-extension ".go")
  )

(use-package projectile-speedbar
  :ensure t
  :disabled t)

;;
;; company
;;
(use-package company
  :ensure t
;  :diminish (company-mode . " C")
  :bind
  (:map company-active-map
	("C-n" . company-select-next)
	("C-p" . company-select-previous)
	("<tab>" . company-complete-common-or-cycle)
	:map company-search-map
	("C-p" . company-select-previous)
	("C-n" . company-select-next)
	)
  :custom
  (company-idle-delay 0)
  (company-echo-delay 0)
  (company-minimum-prefix-length 3)
  :init (global-company-mode)
  :config
  (setq company-backends
	'(
	  (company-files company-keywords company-capf company-yasnippet)
	  (company-abbrev compnay-dabbrev)
	  )
	)
  )

;;
;; flycheck
;;
(use-package flycheck
  :ensure t
  :init (global-flycheck-mode)
  )


;;
;; yasnippet
;;

(use-package yasnippet
  :ensure t
;  :diminish (yas-minor-mode . " Y")
  :config
  (yas-global-mode)
  (use-package yasnippet-snippets :ensure t)
  )


;;
;; auto insert
;;
;(use-package autoinsert
;  :ensure t
;  :config
;  (setq auto-insert-query nil)
;  (setq auto-insert-directory (locate-user-emacs-file "template"))
;  (add-hook 'find-file-hook 'auto-insert)
;  (auto-insert-mode t)
;  )

;;
;; nyan-mode
;;

(use-package nyan-mode
  :ensure t
  :config
  (nyan-mode)
  )

;;
;; projectile
;;
(use-package counsel-projectile
  :ensure t
  :bind (("C-S-f" . counsel-projectile-rg))
  :config
  (use-package projectile
	:ensure t
	:config
	(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
	(projectile-mode +1))
  (counsel-projectile-mode))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; go
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(load "~/.emacs.d/lisp/go.el")

(provide 'init)
;;; init.el ends here
